package com.gopay.common.riskcontrol.dao.impl;

import com.gopay.common.base.dao.impl.BaseReadDAOImpl;
import com.gopay.common.domain.riskcontrol.RcQuickpayModelSwitch;
import com.gopay.common.riskcontrol.dao.RcQuickpayModelSwitchQueryDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author gaocl
 * Created by gaocl on 2017/11/17.
 */
@Repository("rcQuickpaySwitchQueryDAO")
public class RcQuickpayModelSwitchQueryDaoImpl extends BaseReadDAOImpl<RcQuickpayModelSwitch,String> implements RcQuickpayModelSwitchQueryDao {
    @Override
    public RcQuickpayModelSwitch findQuickPayModelSwitch(String modelType) {
        DetachedCriteria criteria = DetachedCriteria.forClass(RcQuickpayModelSwitch.class);
        criteria.add(Restrictions.eq("modelType", modelType));
        List<RcQuickpayModelSwitch> result = findByCriteria(criteria);
        return result == null ? null : result.get(0) ;
    }

@Override
    public RcQuickpayModelSwitch getQuickPayModelByStat(String modelType,String stat){
        String hql=" from RcQuickpayModelSwitch t where t.modelType=:modelType and t.stat=:stat ";
        Map<String, Object> param = new HashMap<>();
        param.put("modelType", modelType);
        param.put("stat", stat);
        List<RcQuickpayModelSwitch> list=this.findByHql(hql, param);
        if(list!=null && !list.isEmpty()){
            return list.get(0);
        }
        return null;
    }

}
